<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .router-link-active{
      background:red;
    }
    .news .router-link-exact-active{
      background-color: blue;
    }
  </style>
</head>
<body>
  <div id="app">
    <router-link tag="button" to="/home">
      首页
    </router-link>
    <router-link tag="button"  to="/news">
      新闻页
    </router-link>
    <router-link tag="button" to="/about">
      关于我们
    </router-link>
      
      <hr>
    <router-view/> 
  
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>
  <script>
    
   const Home = {
     template: `
      <div>
        home页  
      </div>
     `
   }
   const About = {
     template: `
      <div>
        关于我们  
      </div>
     `
   }
   const News = {
     template: `
      <div class="news">
        新闻页  
        <br>
        <router-link to="/news/native">国内新闻</router-link>
        <router-link to="/news/abroad">国外新闻</router-link>
        <hr>
        <router-view />
      </div>
     `
   }

  //  国内新闻

  const NativeNews = {
    template: `
      <div>国内新闻</div>
    `
  }
  // 国外新闻
  const AbroadNews = {
    template: `
      <div>国外新闻</div>
    `
  }
  
  const routes = [ // 配置路由规则
      {
        path: '/home',
        component: Home
      },
      {
        path: '/news',
        component: News,
        children: [
          {
            path: '/news/native',
            component: NativeNews
          },
          {
            path: '/news/abroad',
            component: AbroadNews
          }
        ]
      },
      {
        path: '/about',
        component: About
      }
    ]
  //  定义路由
  const router = new VueRouter({
    routes
  })
    const vm = new Vue({
      el: '#app',
      router
    })

  </script>
</body>
</html>